import { defineEventHandler, getQuery } from 'h3';

export default defineEventHandler(async (event) => {
  const query = getQuery(event);
  const { resourceId, pageNo = 1, pageSize = 10, enabled, status } = query;

  // 资源能力关联数据
  const resourceCapabilities = [
    // 酒店主楼资源的能力配置
    {
      id: 1,
      resource_id: 1,
      capability_id: 1,
      enabled: true,
      priority: 95,
      custom_config: {
        customParameters: {
          maxRooms: 200,
          enableAutoAssignment: true,
        },
      },
      status: 'active',
      assigned_by: 'admin',
      assigned_time: '2024-01-01 00:00:00',
      created_by: 'admin',
      created_time: '2024-01-01 00:00:00',
      updated_by: 'admin',
      updated_time: '2024-01-01 00:00:00',
      deleted: 0,
      // 关联的能力信息
      capability: {
        id: 1,
        code: 'ROOM_MANAGEMENT',
        name: '客房管理能力',
        description: '提供客房状态管理、房态更新、房间分配等核心能力',
        icon: 'ant-design:home-outlined',
        color: '#52c41a',
        type: 'business',
        category: 'hotel',
      },
    },
    {
      id: 2,
      resource_id: 1,
      capability_id: 2,
      enabled: true,
      priority: 90,
      custom_config: {
        customParameters: {
          enableOverbooking: true,
          maxOverbookingRate: 0.1,
        },
      },
      status: 'active',
      assigned_by: 'admin',
      assigned_time: '2024-01-01 00:00:00',
      created_by: 'admin',
      created_time: '2024-01-01 00:00:00',
      updated_by: 'admin',
      updated_time: '2024-01-01 00:00:00',
      deleted: 0,
      capability: {
        id: 2,
        code: 'BOOKING_MANAGEMENT',
        name: '预订管理能力',
        description: '提供客房预订、订单处理、预订确认等业务能力',
        icon: 'ant-design:calendar-outlined',
        color: '#1890ff',
        type: 'business',
        category: 'hotel',
      },
    },
    {
      id: 3,
      resource_id: 1,
      capability_id: 5,
      enabled: true,
      priority: 75,
      custom_config: {
        customParameters: {
          responseTime: '5min',
          enableAutoEscalation: true,
        },
      },
      status: 'active',
      assigned_by: 'admin',
      assigned_time: '2024-01-01 00:00:00',
      created_by: 'admin',
      created_time: '2024-01-01 00:00:00',
      updated_by: 'admin',
      updated_time: '2024-01-01 00:00:00',
      deleted: 0,
      capability: {
        id: 5,
        code: 'GUEST_SERVICE',
        name: '客人服务能力',
        description: '提供客人服务请求、客房服务、投诉处理等能力',
        icon: 'ant-design:customer-service-outlined',
        color: '#eb2f96',
        type: 'business',
        category: 'hotel',
      },
    },
    {
      id: 4,
      resource_id: 1,
      capability_id: 7,
      enabled: true,
      priority: 85,
      custom_config: {
        customParameters: {
          syncInterval: '5min',
          enableRealTimeSync: true,
        },
      },
      status: 'active',
      assigned_by: 'admin',
      assigned_time: '2024-01-01 00:00:00',
      created_by: 'admin',
      created_time: '2024-01-01 00:00:00',
      updated_by: 'admin',
      updated_time: '2024-01-01 00:00:00',
      deleted: 0,
      capability: {
        id: 7,
        code: 'PMS_INTEGRATION',
        name: 'PMS系统集成能力',
        description: '提供与酒店PMS系统的数据同步和业务集成能力',
        icon: 'ant-design:api-outlined',
        color: '#1890ff',
        type: 'technical',
        category: 'integration',
      },
    },
    {
      id: 5,
      resource_id: 1,
      capability_id: 8,
      enabled: true,
      priority: 80,
      custom_config: {
        customParameters: {
          enableRefund: true,
          enablePartialRefund: true,
        },
      },
      status: 'active',
      assigned_by: 'admin',
      assigned_time: '2024-01-01 00:00:00',
      created_by: 'admin',
      created_time: '2024-01-01 00:00:00',
      updated_by: 'admin',
      updated_time: '2024-01-01 00:00:00',
      deleted: 0,
      capability: {
        id: 8,
        code: 'PAYMENT_GATEWAY',
        name: '支付网关能力',
        description: '提供多种支付方式集成和支付处理能力',
        icon: 'ant-design:credit-card-outlined',
        color: '#52c41a',
        type: 'technical',
        category: 'payment',
      },
    },
    // 酒店管理系统资源的能力配置
    {
      id: 6,
      resource_id: 10,
      capability_id: 1,
      enabled: true,
      priority: 90,
      custom_config: {
        customParameters: {
          enableRealTimeSync: true,
          autoStatusTransition: true,
        },
      },
      status: 'active',
      assigned_by: 'admin',
      assigned_time: '2024-01-01 00:00:00',
      created_by: 'admin',
      created_time: '2024-01-01 00:00:00',
      updated_by: 'admin',
      updated_time: '2024-01-01 00:00:00',
      deleted: 0,
      capability: {
        id: 1,
        code: 'ROOM_MANAGEMENT',
        name: '客房管理能力',
        description: '提供客房状态管理、房态更新、房间分配等核心能力',
        icon: 'ant-design:home-outlined',
        color: '#52c41a',
        type: 'business',
        category: 'hotel',
      },
    },
    {
      id: 7,
      resource_id: 10,
      capability_id: 2,
      enabled: true,
      priority: 95,
      custom_config: {
        customParameters: {
          enableOverbooking: true,
          maxOverbookingRate: 0.1,
        },
      },
      status: 'active',
      assigned_by: 'admin',
      assigned_time: '2024-01-01 00:00:00',
      created_by: 'admin',
      created_time: '2024-01-01 00:00:00',
      updated_by: 'admin',
      updated_time: '2024-01-01 00:00:00',
      deleted: 0,
      capability: {
        id: 2,
        code: 'BOOKING_MANAGEMENT',
        name: '预订管理能力',
        description: '提供客房预订、订单处理、预订确认等业务能力',
        icon: 'ant-design:calendar-outlined',
        color: '#1890ff',
        type: 'business',
        category: 'hotel',
      },
    },
    {
      id: 8,
      resource_id: 10,
      capability_id: 5,
      enabled: true,
      priority: 80,
      custom_config: {
        customParameters: {
          responseTime: '3min',
          enableAutoEscalation: true,
        },
      },
      status: 'active',
      assigned_by: 'admin',
      assigned_time: '2024-01-01 00:00:00',
      created_by: 'admin',
      created_time: '2024-01-01 00:00:00',
      updated_by: 'admin',
      updated_time: '2024-01-01 00:00:00',
      deleted: 0,
      capability: {
        id: 5,
        code: 'GUEST_SERVICE',
        name: '客人服务能力',
        description: '提供客人服务请求、客房服务、投诉处理等能力',
        icon: 'ant-design:customer-service-outlined',
        color: '#eb2f96',
        type: 'business',
        category: 'hotel',
      },
    },
    {
      id: 9,
      resource_id: 10,
      capability_id: 7,
      enabled: true,
      priority: 95,
      custom_config: {
        customParameters: {
          syncInterval: '1min',
          enableRealTimeSync: true,
        },
      },
      status: 'active',
      assigned_by: 'admin',
      assigned_time: '2024-01-01 00:00:00',
      created_by: 'admin',
      created_time: '2024-01-01 00:00:00',
      updated_by: 'admin',
      updated_time: '2024-01-01 00:00:00',
      deleted: 0,
      capability: {
        id: 7,
        code: 'PMS_INTEGRATION',
        name: 'PMS系统集成能力',
        description: '提供与酒店PMS系统的数据同步和业务集成能力',
        icon: 'ant-design:api-outlined',
        color: '#1890ff',
        type: 'technical',
        category: 'integration',
      },
    },
    {
      id: 10,
      resource_id: 10,
      capability_id: 8,
      enabled: true,
      priority: 90,
      custom_config: {
        customParameters: {
          enableRefund: true,
          enablePartialRefund: true,
        },
      },
      status: 'active',
      assigned_by: 'admin',
      assigned_time: '2024-01-01 00:00:00',
      created_by: 'admin',
      created_time: '2024-01-01 00:00:00',
      updated_by: 'admin',
      updated_time: '2024-01-01 00:00:00',
      deleted: 0,
      capability: {
        id: 8,
        code: 'PAYMENT_GATEWAY',
        name: '支付网关能力',
        description: '提供多种支付方式集成和支付处理能力',
        icon: 'ant-design:credit-card-outlined',
        color: '#52c41a',
        type: 'technical',
        category: 'payment',
      },
    },
  ];

  // 过滤数据
  let filteredData = resourceCapabilities.filter((item) => item.deleted === 0);

  if (resourceId) {
    filteredData = filteredData.filter(
      (item) => item.resource_id === Number(resourceId),
    );
  }

  if (enabled !== undefined) {
    filteredData = filteredData.filter(
      (item) => item.enabled === (enabled === 'true'),
    );
  }

  if (status) {
    filteredData = filteredData.filter((item) => item.status === status);
  }

  // 分页
  const startIndex = (Number(pageNo) - 1) * Number(pageSize);
  const endIndex = startIndex + Number(pageSize);
  const paginatedData = filteredData.slice(startIndex, endIndex);

  return {
    code: 0,
    message: '查询成功',
    data: {
      list: paginatedData,
      total: filteredData.length,
      pageNo: Number(pageNo),
      pageSize: Number(pageSize),
    },
  };
});

